<template>
	<view class="bgcolor" v-if="pageShow">
		<header-top :messageInfo="{typeFlag:true,message:'个人信息页'}">
			<view class="rightmsg" slot="rightmsg">
				<view class="rightmsg_content">
					<view class="top_right_text" @click="change">编辑</view>
				</view>
			</view>
		</header-top>
		<view class="nick">
			<!-- <view style="width: 50px;height: 50px ;border-radius: 50%;background-color:aqua;margin: 0 auto;">		
			</view> -->
			<image :src="upImg[0]" mode="" style="width: 160rpx;height: 160rpx;border-radius: 50%;">
			</image>
		</view>
		<view class="userInfo">
			<view class="flexbetween">
				<text style="color: #999999;">真实姓名</text>
				<text>{{userinfo.bank_name || ""}}</text>
			</view>
			<view class="flexbetween">
				<text style="color: #999999;">性别</text>
				<text>{{userinfo.gender==1?"男":"女"}}</text>
			</view>
			<view class="flexbetween">
				<text style="color: #999999;">生日</text>
				<text>{{userinfo.birthday || ""}}</text>
			</view>
			<view class="flexbetween">
				<text style="color: #999999;">手机号</text>
				<text>{{userinfo.mobile || ""}}</text>
			</view>
			<!-- <view class="flexbetween">
				<text style="color: #999999;">部门</text>
				<text>{{employeesName || ""}}</text>
			</view> -->
			<view class="flexbetween" v-if="userinfo.wechat_code">
				<text style="color: #999999;">微信号</text>
				<text>{{userinfo.wechat_code || ""}}</text>
			</view>
			<view class="flexbetween">
				<text style="color: #999999;">省市区</text>
				<text>{{provice}}/{{city}}</text>
			</view>
			<view class="flexbetween" v-if="userinfo.idcard">
				<text style="color: #999999;">身份证号</text>
				<text>{{userinfo.idcard || ""}}</text>
			</view>
			<view class="" v-if="userinfo.idcard_zimage_text">
				<text style="color: #999999;">身份证头像面</text>
			</view>
			<image :src="userinfo.idcard_zimage_text" mode="" style="width: 336rpx;height: 291rpx;" v-if="userinfo.idcard_zimage_text">
			</image>
			<view class="" v-if="userinfo.idcard_fimage_text">
				<text style="color: #999999;">身份证国徽面</text>
			</view>
			<image :src="userinfo.idcard_fimage_text" mode="" style="width: 336rpx;height: 291rpx;" v-if="userinfo.idcard_fimage_text">
			</image>
			<!-- <view class="flexbetween">
				<text style="color: #999999;">注册时间</text>
				<text >{{userinfo.createtime  || ""}}</text>
			</view> -->
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	import citys from "@/static/city/city.js"
	export default {
		data() {
			return {
				info: {
					name: "你好"
				},
				items:[],
				userinfo: {},
				upImg: [],
				employeesList: [], //部门
				employeesName:"",//部门名称
				provice:"",
				city:"",
				pageShow:false
			}
		},
		onLoad(){
			
		},
		onShow() {
			let arr = JSON.parse(JSON.stringify(citys.data))
			arr.forEach(item => {
				item.children.forEach(value => {
					value.children = []
				})
			})
			this.items = arr
			this.getEmployeesInfo()
		},
		methods: {
			getEmployeesInfo() { //部门
				httpRequest.request('/employeesapi/user/getEmployeesBm', 'GET', {}).then(res => {
					this.employeesList = res.data
					this.getinfo()
				})
			},
			getinfo() { // 个人信息
				httpRequest.request('/employeesapi/user/index', 'POST', {}).then(res => {
					this.upImg.push(res.data.avatar_text)
					let index = this.employeesList.findIndex(item => {
						return item.id==res.data.employees_bm_id
					})
					// this.employeesName=this.employeesList[index].name
					this.items.forEach(item => {
						if (item.value == res.data.province_id) {
							this.provice = item.text
							console.log(this.provice,"999999999999")
						}
						item.children.forEach(ite => {
							if(ite.value==res.data.city_id){
								this.city = ite.text
								console.log(this.city,"999999999999")
							}
						})
					})
					this.userinfo = res.data
					this.pageShow=true
				})
			},
			change() {
				uni.navigateTo({
					url: './changeInfo'
				})
			},
			// 上传详情图片
			upimage() {
				let _this = this;
				let upImgs = _this.upImg;
				let num = 9 - upImgs.length;
				if (num <= 0) {
					console.log(111111111)
					return false;
				}
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						console.log(res)
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(num, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], _this.upImg)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(num, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									console.log(res[i])
									_this.uploadImageService(res[i], _this.upImg)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {
						console.log(res)
					}
				});
			},
			uploadImageService(url, upImg) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					this.upImg = []
					this.upImg.push(image_item);
					httpRequest.request('appapi/staff/user/infoedit', 'POST', {
						type: 2,
						avatar: this.upImg[0]
					}).then(res => {})
				}).catch(err => {
					console.log(444)
				});
			},
		}
	}
</script>

<style scoped lang="scss">
	.nick {
		padding: 30rpx 0;
		width: 100%;
		text-align: center;
		border-bottom: 2rpx solid #F6F6F6;
		height: 160rpx;
		background-color: #fff;
	}

	.userInfo {
		width: 100%;
		padding: 30rpx 20rpx;
		box-sizing: border-box;
		background-color: #fff;

		text {
			padding: 14rpx;
			font-size: 30rpx;
		}
	}
</style>